package com.ecoolex.discount.sales.admin.controller;

import com.ecoolex.discount.sales.ws.PaymentOrderService;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.dubbo.config.annotation.Reference;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


@RestController
@RequestMapping("/payment/order")
public class PaymentOrderController {

    private Logger log = LoggerFactory.getLogger(PaymentOrderController.class);

    @Reference
    private PaymentOrderService paymentOrderService;

    @PostMapping("/notify/pay")
    public Object payNotify(@RequestBody String body) {
        log.debug("微信支付通知[/payment/order/notify/pay]: bydy={}", body);
        return paymentOrderService.orderNotify(body, PaymentOrderController.class.getSimpleName());
    }

    @PostMapping("/notify/refund")
    public Object refundNotify(@RequestBody String body) {
        log.debug("微信退款通知[/payment/order/notify/refund]: bydy={}", body);
        return paymentOrderService.refundNotify(body, PaymentOrderController.class.getSimpleName());
    }
    
    @PostMapping("/nihaopay/notify/pay")
    public void nihaoPayNotify(HttpServletRequest req, HttpServletResponse response) throws Exception{
        log.debug("nihaoPay支付通知[/payment/order/notify/pay]: req={}", req);
        paymentOrderService.nihaoPayOrderNotify(req,response, PaymentOrderController.class.getSimpleName());
    }
}
